package string_question.leecode.test17;

import java.util.ArrayList;
import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/6 19:46
 */
public class Solution2 {

    // 方法二： 再走一个暴力一点的方法(利用集合的remove函数)
    public List<String> letterCombinations(String digits) {
        String[] dic = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
        List<String> res = new ArrayList<>();
        int len = digits.length();
        if (len == 0) return res;
        res.add("");
        for (int i = 0; i < len; i++) {
            int size = res.size();
            char[] cs = dic[digits.charAt(i) - '2'].toCharArray();
            for (int j = 0; j < size; j++) {
                String temp = res.remove(0);
                for (char c : cs) {
                    res.add(temp + c);
                }
            }
        }
        return res;
    }

}
